<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <script type="text/javascript">

function Node(){
this.left=null;
this.right=null;
this.value=null;
}

Node.prototype.add = function(value){
if(value!=null && typeof(value)!='undefined'){
if(this.value==null){
this.value = value;
return;
}

var node = new Node();
node.value=value;
if(this.value>=value){
if(this.left==null){
this.left = node;
}else{
this.left.add(value);
}
}else{
if(this.right==null){
this.right = node;
}else{
this.right.add(value);
}
}
}
}

Node.prototype.print=function(data){
if(this.left!=null){
this.left.print(data);
}
data.push(this.value);
if(this.right!=null){
this.right.print(data);
}
}

function app(){
var data=[2,6,56,152,5,4,4756,200,45,24,85,25,954,5622,5];
var root = new Node();
for(var i=0;i<data.length;i++){
root.add(data[i]);
}
var rs = [];
root.print(rs);
console.log(rs.join(","));
}

app();

</script>
</body>
</html>
